package com.ruoyi.web.controller.example;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.web.pojo.Address;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Anonymous//为了能够匿名访问
@RestController

public class BindController {
//    尝试接受参数

//    http://localhost:8080/GetName?Name=唐明雪&age=22
    @GetMapping("/GetName")
    public String GetName(HttpServletRequest request){
        String name = request.getParameter("Name");
        String age = request.getParameter("age");

        return "获取的姓名是：" + name + "；获取的年龄是" + age;
    }

//    尝试直接获取，需要定义的变量名和url中的参数名 完全一致
    @GetMapping("/GetName2")
    public String GetName2(String name,String age){
        return "获取的姓名是：" + name + "；获取的年龄是" + age;
    }

//    restFul风格
    @GetMapping("/GetName3/{name}")
    public String GetName3(@PathVariable(value = "name") String name){
        return "获取的姓名是：" + name;
    }
    @PostMapping("/GetUserInfo")
    public String GetUserInfo(@RequestBody Address address) {
        String result =
                "用户的姓名是：" + address.getName()
                + "\n用户的编号是：" + address.getSno()
                + "\n用户的电话是：" + address.getTel()
                + "\n用户的订单是：" + address.getOrderId()
                + "\n用户的地址是：" + address.getAddress();
        return result;
    }
}
